home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gximage4.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  4.7 KB  |  161 lines

  1. /* Copyright (C) 1998, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gximage4.c,v 1.3 2000/09/19 19:00:38 lpd Exp $ */
  20. /* ImageType 4 image implementation */
  21. #include "memory_.h"
  22. #include "gx.h"
  23. #include "gserrors.h"
  24. #include "gscspace.h"
  25. #include "gsiparm4.h"
  26. #include "gxiparam.h"
  27. #include "gximage.h"
  28. #include "stream.h"
  29.  
  30. /* Forward references */
  31. private dev_proc_begin_typed_image(gx_begin_image4);
  32.  
  33. /* Structure descriptor */
  34. private_st_gs_image4();
  35.  
  36. /* Define the image type for ImageType 4 images. */
  37. private image_proc_sput(gx_image4_sput);
  38. private image_proc_sget(gx_image4_sget);
  39. private image_proc_release(gx_image4_release);
  40. const gx_image_type_t gs_image_type_4 = {
  41.     &st_gs_image4, gx_begin_image4, gx_data_image_source_size,
  42.     gx_image4_sput, gx_image4_sget, gx_image4_release, 4
  43. };
  44. /*
  45.  * The implementation is shared with ImageType 1, so we don't need our own
  46.  * enum_procs.
  47.  */
  48. /*
  49.   private const gx_image_enum_procs_t image4_enum_procs = {
  50.     gx_image1_plane_data, gx_image1_end_image
  51.   };
  52. */
  53.  
  54. /* Initialize an ImageType 4 image. */
  55. void
  56. gs_image4_t_init(gs_image4_t * pim, const gs_color_space * color_space)
  57. {
  58.     gs_pixel_image_t_init((gs_pixel_image_t *) pim, color_space);
  59.     pim->type = &gs_image_type_4;
  60.     pim->MaskColor_is_range = false;
  61. }
  62.  
  63. /* Start processing an ImageType 4 image. */
  64. private int
  65. gx_begin_image4(gx_device * dev,
  66.         const gs_imager_state * pis, const gs_matrix * pmat,
  67.         const gs_image_common_t * pic, const gs_int_rect * prect,
  68.         const gx_drawing_color * pdcolor, const gx_clip_path * pcpath,
  69.         gs_memory_t * mem, gx_image_enum_common_t ** pinfo)
  70. {
  71.     gx_image_enum *penum;
  72.     const gs_image4_t *pim = (const gs_image4_t *)pic;
  73.     int code = gx_image_enum_alloc(pic, prect, mem, &penum);
  74.  
  75.     if (code < 0)
  76.     return code;
  77.     penum->alpha = gs_image_alpha_none;
  78.     penum->masked = false;
  79.     penum->adjust = fixed_0;
  80.     /* Check that MaskColor values are within the valid range. */
  81.     {
  82.     bool opaque = false;
  83.     uint max_value = (1 << pim->BitsPerComponent) - 1;
  84.     int spp = cs_num_components(pim->ColorSpace);
  85.     int i;
  86.  
  87.     for (i = 0; i < spp * 2; i += 2) {
  88.         uint c0, c1;
  89.  
  90.         if (pim->MaskColor_is_range)
  91.         c0 = pim->MaskColor[i], c1 = pim->MaskColor[i + 1];
  92.         else
  93.         c0 = c1 = pim->MaskColor[i >> 1];
  94.  
  95.         if ((c0 | c1) > max_value)
  96.         return_error(gs_error_rangecheck);
  97.         if (c0 > c1) {
  98.         opaque = true;    /* pixel can never match mask color */
  99.         break;
  100.         }
  101.         penum->mask_color.values[i] = c0;
  102.         penum->mask_color.values[i + 1] = c1;
  103.     }
  104.     penum->use_mask_color = !opaque;
  105.     }
  106.     code = gx_image_enum_begin(dev, pis, pmat, pic, pdcolor, pcpath, mem,
  107.                    penum);
  108.     if (code >= 0)
  109.     *pinfo = (gx_image_enum_common_t *)penum;
  110.     return code;
  111. }
  112.  
  113. /* Serialization */
  114.  
  115. private int
  116. gx_image4_sput(const gs_image_common_t *pic, stream *s,
  117.            const gs_color_space **ppcs)
  118. {
  119.     const gs_image4_t *pim = (const gs_image4_t *)pic;
  120.     bool is_range = pim->MaskColor_is_range;
  121.     int code = gx_pixel_image_sput((const gs_pixel_image_t *)pim, s, ppcs,
  122.                    is_range);
  123.     int num_values =
  124.     gs_color_space_num_components(pim->ColorSpace) * (is_range ? 2 : 1);
  125.     int i;
  126.  
  127.     if (code < 0)
  128.     return code;
  129.     for (i = 0; i < num_values; ++i)
  130.     sput_variable_uint(s, pim->MaskColor[i]);
  131.     *ppcs = pim->ColorSpace;
  132.     return 0;
  133. }
  134.  
  135. private int
  136. gx_image4_sget(gs_image_common_t *pic, stream *s,
  137.            const gs_color_space *pcs)
  138. {
  139.     gs_image4_t *const pim = (gs_image4_t *)pic;
  140.     int num_values;
  141.     int i;
  142.     int code = gx_pixel_image_sget((gs_pixel_image_t *)pim, s, pcs);
  143.  
  144.     if (code < 0)
  145.     return code;
  146.     pim->type = &gs_image_type_4;
  147.     pim->MaskColor_is_range = code;
  148.     num_values =
  149.     gs_color_space_num_components(pcs) *
  150.     (pim->MaskColor_is_range ? 2 : 1);
  151.     for (i = 0; i < num_values; ++i)
  152.     sget_variable_uint(s, &pim->MaskColor[i]);
  153.     return 0;
  154. }
  155.  
  156. private void
  157. gx_image4_release(gs_image_common_t *pic, gs_memory_t *mem)
  158. {
  159.     gx_pixel_image_release((gs_pixel_image_t *)pic, mem);
  160. }
  161.